<?php

namespace App\Console\Commands;

use App\Curl;
use App\User;
use Illuminate\Console\Command;
use Storage;
use DB;

class AddUsers extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'addUsers:addUsers';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'add users(添加虚假用户)';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $i = 1;
        $datas = (scandir(storage_path('avatar/')));
        foreach ($datas as $data) {
            if ($data !== '.' && $data !== '..') {
                $file = storage_path('avatar/' . $data);
                $pic = fopen($file, 'r');
                $filename = "sign_no" . $data . '.png';
                Storage::disk('oss')->put($filename, $pic);
                $path = 'https://rans-7900.oss-cn-beijing.aliyuncs.com/' . $filename;
                $insert[] = [
                    'name' => explode('.', $data)[0],
                    'sex' => $i % 2 ? '男' : '女',
                    'uuid' => Curl::CreateUuid(),
                    'c_avatar' => $path,
                    'create_time' => date('Y-m-d H:i:s', time()),
                    'sign' => User::SIGN_NO
                ];
                $i++;
            }
        }
        DB::table('t_member')->insert($insert);
        exit('ok');
    }
}
